﻿Imports System.Text

Public Class SentenciaSql

    Private registro As Registro
    Private nombreTabla As String

    Public Sub New(ByVal nombreTabla As String, ByRef registro As Registro)
        Me.registro = registro
        Me.nombreTabla = nombreTabla
    End Sub

    Public Function getInsertSql() As String
        Dim sb As New StringBuilder

        sb.Append("insert into ")
        sb.Append(nombreTabla)

        sb.Append("(")
        For Each v As Valor In registro.getValores()
            sb.Append(v.columna)
            sb.Append(",")
        Next
        sb.Remove(sb.Length - 1, 1) 'borrando la ultima coma

        sb.Append(") values (")

        For Each v As Valor In registro.getValores()
            sb.Append(v.getValorSql())
            sb.Append(",")
        Next

        sb.Remove(sb.Length - 1, 1) 'borrando la ultima coma
        sb.Append(")")

        Return sb.ToString()

    End Function


    Public Function getUpdateSql(ByVal where As String) As String
        Dim sb As New StringBuilder

        sb.Append("update ")
        sb.Append(nombreTabla)

        sb.Append(" set ")
        For Each v As Valor In registro.getValores()
            sb.Append(v.columna)
            sb.Append("=")
            sb.Append(v.getValorSql())
            sb.Append(",")
        Next
        sb.Remove(sb.Length - 1, 1) 'borrando la ultima coma

        sb.Append(" ")
        sb.Append(where)

        Return sb.ToString()
    End Function
End Class
